<!DOCTYPE html>
<html lang="zh_CN" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="common/includeAdmin::header('专题管理','')"></head>
<body class="childrenBody">
	<form class="layui-form">
		<blockquote class="layui-elem-quote quoteBox">
			<form class="layui-form">
				<div class="layui-inline">
					<div class="layui-input-inline">
						<input type="text" class="layui-input searchVal"
							placeholder="请输入搜索的内容" />
					</div>
					<a class="layui-btn search_btn" data-type="reload">搜索</a>
				</div>
				<div class="layui-inline">
					<a class="layui-btn layui-btn-normal add">新增</a>
				</div>
				<div class="layui-inline">
					<a class="layui-btn layui-btn-danger layui-btn-normal batchDel">批量删除</a>
				</div>
			</form>
		</blockquote>
		<table id="seriesList" lay-filter="seriesList"></table>

		<!--操作-->
		<script type="text/html" id="seriesBar">
		<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
		<a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del">删除</a>
	</script>
		<!--状态-->
		<script type="text/html" id="stateFormat">
		{{#  if(d.state == "0"){ }}
		<span class="layui-red">禁用</span>
		{{#  } else if(d.state == "1" ){ }}
		<span class="layui-blue">正常</span>
		{{#  } else { }}
			未知
		{{#  }}}
	</script>
	</form>
	<div th:include="common/includeAdmin::footer"></div>
	<script type="text/javascript">
	layui.use([ 'form', 'layer', 'table' ], function() {
		var form = layui.form;
		var $ = layui.jquery;
		var layer = parent.layer === undefined ? layui.layer : top.layer;
		var table = layui.table;

		var tableIns = table.render({
			elem : '#seriesList',
			// url : '/json/sysConfig.json',
			url : "/admin/series/",
			page : true,
			loading : true,
			height : 'full-110',
			limit : 10,
			limits : [ 10, 15, 20, 25 ],
			response:{
	        	countName: 'total'
	        },
			id : "seriesListTable",
			cols : [ [ {
				type : 'checkbox'
			}, {
				field : 'id',width : 100,title : 'ID'
			}, {
				field : 'seriesName',width : 180,title : '专题名称'
			}, {
				field : 'seriesImg',width : 120,title : '专题图片'
			}, {
				field : 'seriesDesc',title : '专题描述',width : 200
			} // minWidth：局部定义当前单元格的最小宽度，layui 2.2.1 新增
			,{
				field : 'sort',width : 120,title : '排序',sort:true
			},{
				field : 'count',width : 120,title : '专题数',sort:true
			},{
				field : 'createDate',title : '创建时间',width : 160,sort : true,
				templet : function(d) {
					return d.createDate.substring(0, 16);
				}
			}, {
				field : 'updateDate',title : '更新时间',minWidth : 160,sort : true,
				templet : function(d) {
					return d.updateDate.substring(0, 16);
				}
			}, {
				title : '操作',width : 170,templet : '#seriesBar',fixed : "right",align : "center"
			} ] ]
		});
		// 列表操作
		table.on('tool(seriesList)', function(obj) {
			var layEvent = obj.event, data = obj.data;
			var state = 0;
			if (layEvent === 'edit') { // 编辑
				addData(data);
			} else if (layEvent === 'del') { // 删除
				layer.confirm('确定删除此分类,如果专题下面有文章也会被删除？', {
					icon : 3,
					title : '提示信息'
				}, function(index) {
					remove(data.id);
					tableIns.reload();
					layer.close(index);
					// })
				});
			}
		});
		function addData(edit){
			 var index = layui.layer.open({
	             title : '添加信息',
	             type : 2,
	             content : '/admin/series/save',
	             area: ['600px', '400px'],
	             resize:false,  //是否运行拉伸  true表示允许
	             scrollbar:false,
	             anim:1,
	             btn:['确定','取消'],
	             yes:function(index,layero){
	                 //点击确定获取子页面参数
	             	var body = layui.layer.getChildFrame('body',index);
	             	//alert("form:"+childrenBody.contents().find('.configAdd'));
	             	var param ={
	             			"id":edit==null?"":edit.id,
	             			"seriesName":body.find(".seriesName").val(),
	             			"seriesImg":body.find(".seriesImg").val(),
	             			"seriesDesc":body.find(".seriesDesc").val(),
	             			"sort":body.find(".sort").val(),
	             	}
	             	B.post({
	             		url:"/admin/series/",
						loading:true,
						data:param,
						success:function(data){
							if(data.success){
								B.msg("保存成功");
								tableIns.reload();
							}else{
								B.msg(data.msg);
							}
							layui.layer.close(index);
						}
	             	});
	             },
	             btn2:function(index,layero){
	             	layui.layer.close(index);
	             	//parent.layer.alert('点击了取消');
	             },
	             success : function(layero, index){
	             	var body = layui.layer.getChildFrame('body', index);
	             	 if(edit){
		                    body.find(".seriesName").val(edit.seriesName);  
		                    body.find(".seriesImg").val(edit.seriesImg);  
		                    body.find(".seriesDesc").val(edit.seriesDesc);
		                    body.find(".sort").val(edit.sort); 
		                    form.render();
		                }
	             	setTimeout(function(){
	                    layui.layer.tips('点击此处返回列表', '.layui-layer-setwin .layui-layer-close', {
	                        tips: 3
	                    });
	                },200)
					layui.layer.iframeAuto(index);//设置页面自适应
	             }
	             
	         });
		}
		function remove(id){
			B.del({
				url:"/admin/series/"+id,
				loading:true,
				success:function(data){
					B.msg(data.msg);
					tableIns.reload();
				}
			});
		}
		$(".add").click(function(){
			addData();
		});
		$(".search_btn").click(function() {
			if($(".searchVal").val() != ''){
	            table.reload("seriesListTable",{
	                page: {
	                    curr: 1 //重新从第 1 页开始
	                },
	                where: {
	                    seriesName: $(".searchVal").val()  //搜索的关键字
	                }
	            })
	        }else{
	            layer.msg("请输入搜索的内容");
	        }
		});
		$('.batchDel').click(function(){
			var checkStatus = table.checkStatus('seriesListTable'),
	        data = checkStatus.data,
	        ids = [];
		    if(data.length > 0) {
		        for (var i in data) {
		            ids.push(data[i].id);
		        }
		        layer.confirm('确定删除选中的数据？', {icon: 3, title: '提示信息'}, function (index) {
		        	B.del({
						url:"/admin/series/"+ids,
						loading:true,
						success:function(data){
							B.msg(data.msg);
							tableIns.reload();
		            		layer.close(index);
						}
					});
		            // })
		        })
		    }else{
		        layer.msg("请选择需要删除数据");
		    }
		});
	})
	
	
	</script>
</body>
</html>

